package org.example.domain.response;

import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class ResponseResult<T> {

    private String code;
    private String msg;
    private T data;

    public static <T> ResponseResult<T> success(T data) {
        return new ResponseResult<>(ResponseResultEnum.SUCCESS.getCode(), ResponseResultEnum.SUCCESS.getMsg(), data);
    }

    public static <T> ResponseResult<T> success(String msg, T data) {
        return new ResponseResult<>(ResponseResultEnum.SUCCESS.getCode(), msg, data);
    }
    public static ResponseResult<?> failed(String msg) {
        return new ResponseResult<>(ResponseResultEnum.COMMON_FAILED.getCode(), msg, null);
    }

    public static ResponseResult<?> failed() {
        return new ResponseResult<>(ResponseResultEnum.COMMON_FAILED.getCode(), ResponseResultEnum.COMMON_FAILED.getMsg(), null);
    }

    public static ResponseResult<?> failed(String code, String msg) {
        return new ResponseResult<>(code, msg, null);
    }

    public static ResponseResult<?> failed(ResponseResultEnum errorResult) {
        return new ResponseResult<>(errorResult.getCode(), errorResult.getMsg(), null);
    }

    public static <T> ResponseResult<T> instance(String code, String message, T data) {
        ResponseResult<T> result = new ResponseResult<>();
        result.setCode(code);
        result.setMsg(message);
        result.setData(data);
        return result;
    }

}
